package com.sljy.hzk.ui.exam;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.afollestad.materialdialogs.MaterialDialog;
import com.example.api.InjectParam;
import com.sljy.hzk.R;
import com.sljy.hzk.annotation.ActivityInfo;
import com.sljy.hzk.base.BaseActivity;
import com.sljy.hzk.entity.ExamInfosEntity;
import com.sljy.hzk.entity.SignEntity;
import com.sljy.hzk.net.BaseCallBack;
import com.sljy.hzk.net.HttpConfig;
import com.sljy.hzk.net.HttpHeper;
import com.sljy.hzk.net.service.ExamService;
import com.trello.rxlifecycle2.android.ActivityEvent;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.sljy.hzk.annotation.ActivityInfo.TITLE_TWO_LEVEL;

@ActivityInfo(layout = R.layout.activity_exam_yz, title = "身份验证", titleLevel = TITLE_TWO_LEVEL)
public class ExamYzActivity extends BaseActivity {
    @InjectParam
    String examId;
    @BindView(R.id.name)
    EditText nameEdit;
    @BindView(R.id.num)
    EditText numEdit;

    @Override
    protected void init() {
        ExamYzActivity__JumpCenter.bind(this);
    }

    @OnClick(R.id.tv_up)
    public void onViewClicked() {
        String name = nameEdit.getText().toString();
        if (TextUtils.isEmpty(name)){
            showToast("请填写姓名");
        }
        String num = numEdit.getText().toString();
        if (TextUtils.isEmpty(num)){
            showToast("请填写身份证号码");
        }
        //签到
        if(examId.contains("?0"))
            HttpHeper.get().create(ExamService.class).
                    checkUser(examId.substring(0, examId.length() - 2), name, num,12)
                    .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
                    .compose(getThread())
                    .subscribe(new BaseCallBack<Object>(this) {
                        @Override
                        public void onCallBackSuccess(Object result) {
                             if(Integer.parseInt(result.toString()) == 200)showToast("签到成功");
                             else showToast("签到失败");
                             finish();
                        }
                        @Override
                        public void onFail(String mes) {
                            showToast("签到失败");
                        }
                    });
        else{
            ExamDoActivity__JumpCenter.builder(ExamYzActivity.this).setExamId(examId).create().go();
        }

    }
}
